package security.SecurityUtil.login;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * UserDetails
 * @author ygw
 * 2018年10月15日
 */
public class CustomerUserDetails implements UserDetails {

    private static final long serialVersionUID = -1031671631783261102L;
	private  String saId;
    private  String username;
    private  String password;
    private  String type;
    private  boolean isAccountNonLocked;
    private  boolean isEnabled;
    private  boolean isAccountNonExpired;
    
    private  Collection<? extends GrantedAuthority> authorities;

    public CustomerUserDetails(
            String saId,
            String username,
            String password,
            String type,
            boolean isAccountNonLocked,
            boolean isEnabled,
            boolean isAccountNonExpired,
            Collection<? extends GrantedAuthority> authorities
    		) {
        this.saId = saId;
        this.username = username;
        this.password = password;
        this.type = type;
        this.isAccountNonLocked = isAccountNonLocked;
        this.isEnabled = isEnabled;
        this.isAccountNonExpired = isAccountNonExpired;
        this.authorities = authorities;
    }
    //返回分配给用户的角色列表
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }


	public String getSaId() {
        return saId;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }
    	
    public String getType() {
        return type;
    }
  
    // 账户是否未锁定
    @Override
    public boolean isAccountNonLocked() {
        return isAccountNonLocked;
    }
    // 账户是否可用
    @Override
    public boolean isEnabled() {
        return isEnabled;
    }
    // 账户是否未过期
    @Override
    public boolean isAccountNonExpired() {
        return isAccountNonExpired;
    }
    // 密码是否未过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    } 
    
    @Override
	public String toString() {
		return this.getUsername();
	}
	
	@Override
	public int hashCode() {
		return this.getUsername().hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		return this.toString().equals(obj.toString());
	}

}
